package com.cjm.one.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.entity.GoodsCart;
import com.cjm.one.model.goods.vo.GoodsSkuCartVo;
import com.cjm.one.service.GoodsCartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "购物车", description = "购物车")
@RequestMapping("/api/goods/cart")
public class GoodsCartController {
    @Resource
    private GoodsCartService goodsCartService;

    @GetMapping("/list")
    @Operation(summary = "获取购物车列表")
    public Result<Page<GoodsSkuCartVo>> getCartList(@RequestParam(value = "current", defaultValue = "1") Integer current,
                                                    @RequestParam(value = "size", defaultValue = "10") Integer size){
        return goodsCartService.getCartList(current, size);
    }
    @PostMapping("/add")
    @Operation(summary = "添加购物车")
    public Result<Long> addCart(@RequestBody GoodsCart cart){

        return goodsCartService.addCart(cart);
    }
    @PostMapping("/update")
    @Operation(summary = "更新购物车")
    public Result<Boolean> updateCart(@RequestBody GoodsCart cart){
        return goodsCartService.updateCart(cart);

    }
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除购物车")
    public Result<Boolean> deleteCart(@PathVariable("id") Long id){
        return goodsCartService.deleteCart(id);

    }
    @DeleteMapping("/delete/all")
    @Operation(summary = "删除购物车全部商品")
    public Result<Boolean> deleteCartAll(){
        return goodsCartService.deleteCartAll();
    }
    @DeleteMapping("/delete/batch")
    @Operation(summary = "批量删除购物车")
    public Result<Boolean> deleteCartBatch(@RequestParam("ids") Long[] ids){
        return goodsCartService.deleteCartBatch(ids);
    }
    @GetMapping("/all/list")
    @Operation(summary = "获取购物车全部商品")
    public Result<List<GoodsCart>> getAllCartList() {
        return goodsCartService.getAllCartList();
    }
    @GetMapping("/{ids}")
    @Operation(summary = "根据id获取购物车商品")
    public Result<Page<GoodsSkuCartVo>> getCart(@PathVariable("ids") Long[] ids){
        return goodsCartService.getCartListByIds(ids);
    }
}
